package weixin.core.controller;

import com.github.sd4324530.fastweixin.api.MenuAPI;
import com.github.sd4324530.fastweixin.api.OauthAPI;
import com.github.sd4324530.fastweixin.api.entity.Menu;
import com.github.sd4324530.fastweixin.api.entity.MenuButton;
import com.github.sd4324530.fastweixin.api.enums.MenuType;
import com.github.sd4324530.fastweixin.api.enums.OauthScope;
import com.github.sd4324530.fastweixin.api.enums.ResultType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lxb on 2015/12/22.
 */
@Controller
@RequestMapping("/menu")
public class MenuController {
    private static final Logger LOG  = LoggerFactory.getLogger(MenuController.class);
    @Autowired
    private MenuAPI MenuAPI;
    @Autowired
    private OauthAPI OauthAPI;
    @RequestMapping("createMenu")
    @ResponseBody
    public ResultType createMenu(){
        Menu menu=new Menu();
        List<MenuButton> buttons=new ArrayList<MenuButton>();
        MenuButton menuButton=new MenuButton();
        MenuButton menuButton1=new MenuButton();
        MenuButton menuButton2=new MenuButton();
        menuButton.setType(MenuType.CLICK);
        menuButton.setName("第一个菜单");
        menuButton.setKey("1-1");
        menuButton.setUrl(OauthAPI.getOauthPageUrl("http://bb15662683581.vicp.cc/sdktest/jssdk", OauthScope.SNSAPI_USERINFO,"001"));
        menuButton1.setType(MenuType.CLICK);
        menuButton1.setName("第二个菜单");
        menuButton1.setKey("2-1");
        menuButton2.setType(MenuType.CLICK);
        menuButton2.setName("第三个菜单");
        menuButton2.setKey("3-1");
        buttons.add(menuButton);
        buttons.add(menuButton1);
        buttons.add(menuButton2);
        menu.setButton(buttons);
        ResultType type = MenuAPI.createMenu(menu);
        return type;
    }

    /**
     * 删除所有目录
     * @return
     */
    @RequestMapping("delMenu")
    @ResponseBody
    public String delMenu(){
        MenuAPI.deleteMenu();
        return "success";
    }
}
